package com.alquimia.identityaccess.domain.model;



import com.alquimia.domain.Identificador;

import java.io.Serializable;

/**
 * Created by Ivo on 12/07/2014.
 */
public class Person extends Identificador implements Serializable{

    private static final long serialVersionUID = 1L;

    private FullName fullName;
    private EmailAddress emailAddress;
    private User user;

    public Person(FullName aFullName, EmailAddress aEmailAddress) {

        this();
        setEmailAddress(aEmailAddress);
        setFullName(aFullName);
    }

    public void changeFullName(FullName aFullName) {
        this.setFullName(aFullName);
    }

    public void changeEmailAddress(EmailAddress aEmailAddress) {
        this.setEmailAddress(aEmailAddress);
    }

    public FullName fullName() {
        return this.fullName;
    }

    public EmailAddress emailAddress() {
        return this.emailAddress;
    }

    private void setFullName(FullName aFullName) {

        if (aFullName == null)
            throw new NullPointerException("El firstName completo no puede ser nulo.");

        this.fullName = aFullName;
    }

    private void setEmailAddress(EmailAddress aEmailAddress) {

        if (aEmailAddress == null)
            throw new NullPointerException("El emailAddress no puede ser nulo.");

        this.emailAddress = aEmailAddress;
    }

    public void internalOnlySetUser(User aUser){

        this.user = aUser;
    }

    public User user() {
        return this.user;
    }


    protected Person() {
        super();
    }

    @Override
    public boolean equals(Object anObject) {
        boolean equalObjects = false;

        if (anObject != null && this.getClass() == anObject.getClass()) {
            Person typedObject = (Person) anObject;
            equalObjects = this.user().username().equals(typedObject.user().username());
        }

        return equalObjects;
    }

    @Override
    public int hashCode() {
        int hashCodeValue =
                +(90113 * 223)
                        + this.user().username().hashCode();

        return hashCodeValue;
    }

    @Override
    public String toString() {
        return "Person [fullName=" + fullName + ", emailAddress=" + emailAddress + "]";
    }



}
